package validate

import "github.com/cloudwego/hertz/pkg/app/server/binding"

type ValidateError struct {
	ErrType, FailField, Msg string
}

// Error implements error interface.
func (e *ValidateError) Error() string {
	if e.Msg != "" {
		//return e.ErrType + ": expr_path=" + e.FailField + ", cause=" + e.Msg
		return e.Msg
	}
	//return e.ErrType + ": expr_path=" + e.FailField + ", cause=invalid"
	return "invalid"
}

func NewValidateConfig() *binding.ValidateConfig {
	validateConfig := &binding.ValidateConfig{}
	validateConfig.SetValidatorErrorFactory(func(failField, msg string) error {
		err := ValidateError{
			ErrType:   "validateErr",
			FailField: failField,
			Msg:       msg,
		}

		return &err
	})
	return validateConfig
}
